using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class User_DSSP : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Load1SP();
    }

    #region"Load1SP"
    public void Load1SP()
    {
        

        tbSanPhamCollection sanPhamCollection = tbSanPhamBUS.GetAll();
        Repeater2.DataSource = sanPhamCollection;
        Repeater2.DataBind();

    }
    #endregion
    protected void bt_login_DangNhap_Click(object sender, EventArgs e)
    {

    }

    public int ma;
    protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
      e.Item.ItemType == ListItemType.Item)
        {
            
            tbSanPham sanPham = (tbSanPham)e.Item.DataItem;

             ma = sanPham.MaSP;
            Image img_HinhAnh = (Image)e.Item.FindControl("img_HinhAnh");

            tbHinhAnh cthinhanh = tbHinhAnhBUS.GetByMaSP(sanPham.MaSP);
            if (cthinhanh == null)
            {
                img_HinhAnh.ImageUrl = "~/Photos/" + "no_images.jpg";
            }
            else
            {
                tbHinhAnh hinhAnh = tbHinhAnhBUS.GetByID(cthinhanh.MaHA);
                img_HinhAnh.ImageUrl = "~/Photos/" + hinhAnh.Link;

            }

            Literal lit_moTa = (Literal)e.Item.FindControl("lit_moTa");
            lit_moTa.Text = sanPham.MoTa;

            Literal lit_giamGa = (Literal)e.Item.FindControl("lit_giamGia");

            double tam = (sanPham.GiaBan * 100) / sanPham.GiaGoc;

            lit_giamGa.Text = Math.Floor(tam).ToString();
        }

    }
}
